#pragma once

#include "Base/AbstractProgressProcedure.h"
#include <QObject>
#include <Assert.h>

#include <AliOSSAdapter.h>

namespace TC
{
    class Connection;
    namespace Request
    {
        using namespace AliOSS;
        /*! Upload a file
         * After remotePath changed, uploader could be deleted, uploading will continue.
         * */
        class TCCORE_EXPORT FileUploader : public AbstractProgressProcedure
        {
            Q_OBJECT
                Q_PROPERTY(QString remoteUrl READ remoteUrl NOTIFY remoteUrlChanged)
		public:
			Q_INVOKABLE void upload(const QString &filepath);
			Q_INVOKABLE void uploadString(const QString &strs, const QString &suffix = QString());
			Q_INVOKABLE void uploadData(const QByteArray &data, const QString &suffix = QString());
        public:
            QString remoteUrl() { return _remogeUrl; }
        public:
            void setRemoteUrl(QString newVal) { if (_remogeUrl != newVal) { _remogeUrl = newVal; remoteUrlChanged(); } }
        public:
            Q_SIGNAL void remoteUrlChanged();
        protected:
            void onUploadProgress(qint64 bytesSent, qint64 bytesTotal);
            void onSocketReadyRead(AliOSSUploadRequest *uploader, Connection *socket);
			void onSocketDisconnected();
        public:
            static void initGlobal();
        private:
            QString _remogeUrl;
            static AliOSSAdapter *adapter;

        };
    }
}

